package com.method.Test;

/*
需求:设计一个方法用于获取数组中元素的最大值
 */
public class Test07 {
    public static void main(String[] args) {
        int[] arr = {11, 2, 3, 4, 55, 66, 77,};
        int max = getMax(arr);
        System.out.println("最大值是" + max);
        int min = getMin(arr);
        System.out.println("最小值是" + min);
        int[] arr2 = {11, 22, 33, 44, 55, 66};
        int max1 = getMax(arr2);
        System.out.println("最大值是" + max1);
        int min1 = getMin(arr2);
        System.out.println("最小值是" + min1);

    }

    public static int getMax(int[] arr) {
        int max = arr[0];
        for (int i = 0; i < arr.length; i++) {
            //  arr[i]
            if (arr[i] > max) {
                max = arr[i];
            }
        }
        return max;


    }

    public static int getMin(int[] arr) {
        int min = arr[0];
        for (int i = 0; i < arr.length; i++) {
            //arr[i]
            if (arr[i] < min) {
                min = arr[i];
            }
        }
        return min;
    }


}
